package edu.jmu.springmvc;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;



@Controller
@RequestMapping("/user1")
public class UserController1 {
	
	@RequestMapping("/handle82")
	public @ResponseBody String handle82(User user){
		System.out.println("UserController.handle82():"+user);
		return user.toString();
	}
	
	@RequestMapping(value="/register",method=RequestMethod.GET)
	public String register(User1 user1){
		System.out.println("进入注册页面!");
		return "UserRegister";
	}
	
	@RequestMapping(value="/register",method=RequestMethod.POST)
	public String doRegister(User1 user1){
		System.out.println("正在保存用户!");
		System.out.println(user1);
		return "user1";
	}
	
	@RequestMapping(value="/showUserListByXlsx")
	public String showUserListExcel(ModelMap mm)
	{
		List<User1> user1List = new ArrayList<User1>();
		User1 user1 = new User1();user1.setFirstName("张");user1.setLastName("三");
		User1 user2 = new User1();user2.setFirstName("李");user2.setLastName("四");
		user1List.add(user1);
		user1List.add(user2);
		mm.addAttribute(user1List);
		return "userListExcel";
	}
	
	@RequestMapping(value="/showUserListByPdf")
	public String showUserListInPdf(ModelMap mm){
		List<User1> user1List = new ArrayList<User1>();
		User1 user1 = new User1();user1.setFirstName("Zhang");user1.setLastName("三");
		User1 user2 = new User1();user2.setFirstName("Li");user2.setLastName("四");
		user1List.add(user1);
		user1List.add(user2);
		mm.addAttribute(user1List);
		return "userListPdf";
	}
	@RequestMapping(value="/showUserListByJson")
	public String showUserListByJson(ModelMap mm) {
		List<User1> user1List = new ArrayList<User1>();
		User1 user1 = new User1();user1.setFirstName("张");user1.setLastName("三");
		User1 user2 = new User1();user2.setFirstName("李");user2.setLastName("四");
		user1List.add(user1);
		user1List.add(user2);
		mm.addAttribute(user1List);
		return "userListJson";
	}
	@RequestMapping(value="/showUserList2ByJson")
	public String showUserList2ByJson(ModelMap mm) {
		List<User1> user1List = new ArrayList<User1>();
		User1 user1 = new User1();user1.setFirstName("张");user1.setLastName("三");
		User1 user2 = new User1();user2.setFirstName("李");user2.setLastName("四");
		user1List.add(user1);
		user1List.add(user2);
		mm.addAttribute(user1List);
		return "userListJson";
	}
	
	@RequestMapping(value="/showUserListMix")
	public String  showUserListMix(ModelMap mm){
		List<User1> user1List = new ArrayList<User1>();
		User1 user1 = new User1();user1.setFirstName("张");user1.setLastName("三");
		User1 user2 = new User1();user2.setFirstName("李");user2.setLastName("四");
		user1List.add(user1);
		user1List.add(user2);
		mm.addAttribute(user1List);
		return "userListMix";
	}
	
	@RequestMapping(value="/showUserListMix1")
	public @ResponseBody List<User1>  showUserListMix1(ModelMap mm){
		List<User1> user1List = new ArrayList<User1>();
		User1 user1 = new User1();user1.setFirstName("张");user1.setLastName("三");
		User1 user2 = new User1();user2.setFirstName("李");user2.setLastName("四");
		user1List.add(user1);
		user1List.add(user2);
		return user1List;
	}
	
}
